<?php

// AclAssistant : Community
class Action_Community_ShowCommunityProfile extends RL_Handler
{

	public function getUrl ()
	{
		return $this->ctx->rh->base_url.$this->data['community_url'].'/edit';
	} // end of function getUrl

	public function getWidgetsConfig ()
	{
		$community_oid = $this->data['comity_oid'];
		$widgets = array();

		$widgets[] = array (
			'name' => 'RssWidget',
			'params' => array(
				'widget_view' => 'WG_RssWidget',
			),
		);

		$widgets[] = array (
			'name' => 'CreateBtnWidget',
			'params' => array(
				'widget_position' => 'createbtn',
				'widget_view' => 'WG_CreateBtnWidget',
			),
		);

		$widgets[] = array (
			'name' => 'UserListWidget',
			'params' => array(
				'widget_position' => 'widgets',
				'widget_view' => 'WG_UserListWidget',
			),
		);

		return $widgets;
	} // end of function getWidgetsConfig

	protected function init()
	{
		$this->rh->UseClass('RL_CyrDate');
		$this->acl_assistant = $this->module->aa;
		$this->ctx->db->begin();

		$this->data = $this->acl_assistant->getInfo();
		//$this->operations = $this->acl_assistant->getAvailableOperations();
	}
	protected function shutdown()
	{
		$this->ctx->db->end();
	}

	public function process ()
	{
		$this->renderCommunityProfile();

		// -- touch visitor stat -- {{{
		// visit community
		$this->ctx->mm->getModel("Visitable", "m")->getVisitable('Community')->visit();
		//
		// -- touch visitor stat -- }}}

	} // end of function process

	public function renderCommunityProfile ()
	{
		// FIXME : 2008-05-28 : lucky
		// этот рендер аналогичен реализованному в StatsWidget

		$view = $this->rh->views->findByName('community_profile');
		$view->data = $this->acl_assistant->template_data;

		$m_uniform = $this->ctx->mm->getModel('Uniform', 'm');

		$community_oid = $this->data['comity_oid'];

		// -- render visitor stat -- {{{
		// visit community
		$v_com = $this->ctx->mm->getModel("Visitable", "m")->getVisitable('Community')->setWhat($community_oid);
		$info = $this->ctx->mm->getModel('Visit', 'm')->getDailyItemsInfo(array('community' => $v_com));

		$visit_info = array();
		foreach ($info as $row) {
			$t = $row;
			$t['what'] = $m_uniform->getFactory('Object')->getUniform($row['what_oid']);
			$t['last'] = RL_CyrDate::newFromTimestamp($row['last_ts']);
			$visit_info[] = $t;
		}
		$view->data['visit_info']['items'] = $visit_info;
		//
		// -- render visitor stat -- }}}

		$uni_community = $m_uniform->getFactory('Object')->getUniform($community_oid);
		$view->data['content'] = $uni_community['profile'];
		$view->data['__widgets__'] = $this->widgets;

		$this->rh->response->setContent( $view );
	} // end of function renderCommunityProfile

}
